home *** CD-ROM | disk | FTP | other *** search
- #ifndef FWONSTAC_H
- #define FWONSTAC_H
-
- //========================================================================================
- //
- // File: FWOnStac.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FW_NATIVE_EXCEPTIONS
-
- #if !defined(FWPRIDEB_H) && defined(FW_BUILD_WIN)
- #include "FWPriDeb.h"
- #endif
-
- #if !defined(__CONDITIONALMACROS__) && defined(FW_BUILD_MAC)
- #include "ConditionalMacros.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- extern "C" int FW_FUNC_ATTR _FW_PrivIsOnStack(void *);
-
- #ifdef FW_BUILD_MAC
-
-
- #if !CFMSYSTEMCALLS && GENERATING68K
- #define FW_NINEWORDINLINE(w1, w2, w3, w4, w5, w6, w7, w8, w9) \
- = {w1,w2,w3,w4,w5,w6,w7,w8,w9}
- // Slow version for use if (_FW_PrivIsOnStack()) xxx; works for near and far data
- extern "C"
- {
- #pragma parameter __D0 _FW_PrivIsOnStack(__A0)
- int _FW_PrivIsOnStack(void *)
- FW_NINEWORDINLINE(0x7000, 0xBFC8, 0x6408, 0xB1F8, 0x0908, 0x6202, 0x7001, 0x4880, 0x48C0);
- }
- /*
- 00000 OnStackCheck PROC
- 00000 ;movea.l a4,a0 ; 4 compiler generated move
- 00000 7000 moveq #0,d0
- 00002 BFC8 cmpa.l a0,a7
- 00004 6408 0000E bcc.s @1
- 00006 B1F8 0908 cmpa.l $908,a0
- 0000A 6202 0000E bhi.s @1
- 0000C 7001 moveq #1,d0
- 0000E @1:
- 0000E 4880 ext.w d0
- 00010 48C0 ext.l d0
- 00012 ENDPROC
- */
- #endif
-
- #if 0
- // Near data version
- extern "C"
- {
- #pragma parameter _FW_PrivIsOnStack(__A0)
- void _FW_PrivIsOnStack(void *)
- FIVEWORDINLINE(0xBFC8, 0x6210, 0xB1F8, 0x0908, 0x620A);
- }
- /*
- 00000 OnStack PROC
- 00000 ;movea.l a4,a0 ; 4 compiler generated move
- 00000 BFC8 cmpa.l a0,a7 ; 6
- 00002 6210 00014 bhi.s @1 ; 10/8
- 00004 B1F8 0908 cmpa.l $908,a0 ; 6
- 00008 620A 00014 bhi.s @1 ; 10/8
- 0000A 2F0C move.l a4,-(a7)
- 0000C 486D 001E pea 30(a5)
- 00010 4EAD 001E jsr 30(a5) ; 18
- 00014 @1:
- 00014 4E71 nop
- 00016 ENDPROC
- */
- #endif
-
- #if 0
- // Far data version for when the code is compiled with the -m option.
- extern "C"
- {
- #pragma parameter _FW_PrivIsOnStack(__A0)
- void _FW_PrivIsOnStack(void *)
- FIVEWORDINLINE(0xBFC8, 0x6218, 0xB1F8, 0x0908, 0x6212);
- }
- /*
- 00000 OnStackFar PROC
- 00000 ;movea.l a4,a0 ; 4 compiler generated move
- 00000 BFC8 cmpa.l a0,a7 ; 6
- 00002 6218 0001C bhi.s @1 ; 10/8
- 00004 B1F8 0908 cmpa.l $908,a0 ; 6
- 00008 6212 0001C bhi.s @1 ; 10/8
- 0000A 2F0C move.l a4,-(a7)
- 0000C 204D movea.l a5,a0
- 0000E D1FC 0001 0000 adda.l #-$FFFF0000,a0
- 00014 4855 pea (a5)
- 00016 4EAD 001E jsr 30(a5) ; 18
- 0001A 504F addq #8,a7
- 0001C @1:
- 0001C 4E71 nop
- 0001E ENDPROC
- */
- #endif
-
- #endif
-
- #ifdef FW_BUILD_WIN
- #ifdef FW_BUILD_WIN16
- //----------------------------------------------------------------------------------------
- // WinGetStackBottom
- //----------------------------------------------------------------------------------------
- inline unsigned short *WinGetStackBottom()
- {
- __emit__(0x8C, 0xD2); // mov DX, SS 2 cycles
- #ifndef __BORLANDC__
- return (void*)
- #endif
- __emit__(0xB8, 0x0E, 0x00); // mov AX, 0Eh 2 cycles
- #ifdef __BORLANDC__
- return ((unsigned short *) MAKELP(_DX, _AX));
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // WinGetStackTop
- //----------------------------------------------------------------------------------------
- inline unsigned short *WinGetStackTop()
- {
- __emit__(0x8C, 0xD2); // mov DX, SS 2 cycles
- #ifndef __BORLANDC__
- return (void*)
- #endif
- __emit__(0xB8, 0x0A, 0x00); // mov AX, 0Ah 2 cycles
- #ifdef __BORLANDC__
- return ((unsigned short *) MAKELP(_DX, _AX));
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_PrivSegmentOf
- //----------------------------------------------------------------------------------------
- inline unsigned short _FW_PrivSegmentOf(void* p)
- {
- return (unsigned short)((unsigned long)p >> 16);
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_PrivOffsetOf
- //----------------------------------------------------------------------------------------
- inline unsigned short _FW_PrivOffsetOf(void* p)
- {
- return (unsigned short) p;
- }
-
- //----------------------------------------------------------------------------------------
- // _FW_PrivIsOnStack
- //----------------------------------------------------------------------------------------
- inline int _FW_PrivIsOnStack(void * p)
- {
- int i;
- if (_FW_PrivSegmentOf(p) != _FW_PrivSegmentOf(&i))
- return 0;
- unsigned short top = *WinGetStackTop();
- unsigned short bot = *WinGetStackBottom();
- unsigned short offset = _FW_PrivOffsetOf(p);
- return (offset>top && offset<bot);
- }
- #endif
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif // FW_USE_NEW_HELPER
-
- #endif
-
-